/**
 * Copyright (C) 2025 pony working team
 * SPDX-License-Identifier: MulanPSL-2.0
 */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __X_COMPILER_H__
#define __X_COMPILER_H__

/* Includes ------------------------------------------------------------------*/
#include <x_common.h> /* as compiler-xxxx.h used __CONCAT */

/* Private includes ----------------------------------------------------------*/
#if defined(__GNUC__) || defined(__clang__)
#include "private/compiler_gnuc.h"
#elif defined(_MSC_VER)
#include "private/compiler_msvc.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions prototypes ---------------------------------------------*/

/**
 * __fls_u32 - find the last set in a uint32_t
 * @x: the numeric value
 */
static __always_inline int __fls_u32(uint32_t x)
{
    return 31 - __clz_u32(x);
}

/**
 * __fls_u64 - find the last set in a uint64_t
 * @x: the numeric value
 */
static __always_inline int __fls_u64(uint64_t x)
{
    return 63 - __clz_u64(x);
}

/* Private defines -----------------------------------------------------------*/

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __X_COMPILER_H__ */
